package NewTmas.Popupmenus;

import NewTmas.FramesandPanels.JobGraphPanel;
import NewTmas.FramesandPanels.LogFileFrame;
import att.grappa.*;

import java.awt.event.InputEvent;

/**
 * Created by IntelliJ IDEA.
 * User: abhatnag
 * Date: 7/15/11
 * Time: 5:07 PM
 * To change this template use File | Settings | File Templates.
 */
public class GraphVizGrappaAdapter extends GrappaAdapter {

    JobGraphPanel jobGraphPanel ;


    public GraphVizGrappaAdapter(JobGraphPanel jgp) {
        this.jobGraphPanel=jgp;
    }


    public void grappaPressed(Subgraph subg, Element elem, GrappaPoint pt, int modifiers, GrappaPanel panel) {
        if((modifiers&(InputEvent.BUTTON2_MASK|InputEvent.BUTTON3_MASK)) != 0 && (modifiers&(InputEvent.BUTTON2_MASK|InputEvent.BUTTON3_MASK)) == modifiers && elem!=null) {

            String task=elem.getName();
            java.awt.geom.Point2D mpt = panel.getTransform().transform(pt,null);

            if(elem.isNode()&& jobGraphPanel.task_status.containsKey(elem.getName())) {
                TaskPopupMenu  popup= new TaskPopupMenu(jobGraphPanel,task) ;
                popup.show(panel,(int)mpt.getX(),(int)mpt.getY());
            }
            }

    }




    public void grappaClicked(Subgraph subg, Element elem, GrappaPoint pt, int modifiers, int clickCount, GrappaPanel panel)  {

        if((modifiers&InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK && elem!=null)
        {
            if(clickCount == 2)

            {
                if(elem.isNode())//&& jobGraphPanel.task_status.containsKey(elem.getName()))
                {

                    new LogFileFrame(jobGraphPanel.job,elem.getName(),jobGraphPanel.date,jobGraphPanel.dtp);

                }


            }
        }



    }


}
